extends Node2D
@onready var Card = preload("res://Scenes/Card.tscn")
@export var Total_Card_Count: int = 20
@export var Hand_Card_Limit: int = 8
@export var Init_Card_Position = Vector2(500,100)
@export var Aim_Card_Position = Vector2(-400,100)
var Hand_Card_Count = 0
var Now_Card_Id = 0
var Hand_Card_Pos = []
var Hand_Card_Exist = []
# Called when the node enters the scene tree for the first time.

func Check_Hand_Card_Limit() -> bool:
	return Hand_Card_Count == Hand_Card_Limit

func Get_Card_Pos() -> int:
	for i in Hand_Card_Limit:
		if !Hand_Card_Exist[i]:
			return i
	return -1

func Draw_Card() -> void:
	var Now_Card = get_child(Now_Card_Id)
	var Now_Id = Get_Card_Pos()
	var Now_Pos = Hand_Card_Pos[Now_Id]
	Now_Card.Final_Position = Now_Pos
	Now_Card.Card_Facing_Up = 1
	Now_Card.Card_In_Hand = 1
	Hand_Card_Exist[Now_Id] = 1
	Now_Card_Id += 1
	Hand_Card_Count += 1
	pass

func Update_Hand_Card() -> void:
	if(!Check_Hand_Card_Limit()):
		Draw_Card()

func _ready() -> void:
	
	for i in Total_Card_Count:
		var New_Card = Card.instantiate()
		# New_Card.Final_Position = Vector2(Aim_Card_Position.x+i*90,Aim_Card_Position.y)
		# New_Card.position = Vector2(Init_Card_Position.x,Init_Card_Position.y)
		New_Card.Final_Position = Init_Card_Position
		New_Card.position = Init_Card_Position
		New_Card.name = "Card" + str(i)
		New_Card.Card_Id = i
		New_Card.Card_Element_Type = 0
		New_Card.Card_Facing_Up = 0
		New_Card.visible = 1
		add_child(New_Card)
		
	for i in Hand_Card_Limit:
		Hand_Card_Exist.append(0)
		Hand_Card_Pos.append(Vector2(Aim_Card_Position.x+i*110,Aim_Card_Position.y))
		
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	Update_Hand_Card()
	pass
